/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package NetworkSender;

import NetworkPackage.*;
import FrameWork.Item;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.StreamConnection;
/**
 *
 * @author mostafaizz
 */
public class MessageSender {
    static MessageSender instance;
    boolean state;
    SecurityHandler encryptor;
    XMLHandler xmlBuilder;
    MessageSender()
    {
        xmlBuilder = XMLHandler.getInstance();
        encryptor = new SecurityHandler();
    }
    public static MessageSender getInstance()
    {
        if(instance == null)
        {
            instance = new MessageSender();
        }
        return instance;
    }
    public Item encryptItem(Item item)
    {
        if(item.getEncryptionEnabled())
        {
            if(!item.getEncrypted())
            {
                item.setData(encryptor.encrypt_decrypt(item.getData(),true));
                item.setEncrypted(true);
            }
        }
        return item;
    }
    public String getXML(Item item)
    {
        return xmlBuilder.buildXML(item);
    }
    public boolean isBusy()
    {
        return state;
    }
    public void addItem(String xmlMsg,StreamConnection strCon)
    {
        try
        {
            OutputStream out = strCon.openOutputStream();
            out.write(xmlMsg.getBytes());
        }catch(IOException ioex)
        {
            
        }
    }
}
